package com.wobangkj.common.api.crud;

import com.wobangkj.common.model.crud.Deliver;
import com.wobangkj.common.service.DeliverService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/deliver")
public class DeliverController {
    @Autowired
    private DeliverService deliverService;

    @PostMapping(value = "/create")
    public Object create(@RequestBody Deliver data) {
        // 创建时间
        data.setCreatetime(Timestamp.valueOf(LocalDateTime.now()));
        Long a=Long.parseLong(data.getDeliverContentId());
        String userId = deliverService.getJobId(a.toString());
        data.setDeliverContentPublisherId(userId);
        return deliverService.create(data);
    }

    @PostMapping(value = "/findById")
    public Object findById(String delivererId,String deliverContentId) {
        return deliverService.findById(delivererId,deliverContentId);
    }


    @PostMapping(value = "/findMy")
    public Object findMy(String id){
        return deliverService.findMy(id);
    }


    @PostMapping(value = "/findToMe")
    public Object findToMe(String id){
        return deliverService.findToMe(id);
    }
}
